package com.shuffle.weixin.main;

import java.util.List;

import net.sf.json.JSONObject;

import com.shuffle.weixin.pojo.AccessToken;
import com.shuffle.weixin.pojo.WeixinUser;
import com.shuffle.weixin.util.WeiXinUtil;

public class WeixinManager {

	public static void main(String[] args) {
		

		//token:2DAuR2KnxcnRmreuJ9LmBff-eOIOUgPZdFa_z0jIERryKtQeceQqlBUsBVF0dIJuW6MkKAxVUwjMyvsO9FXq8ksP95WvCobMmnue8IjO8XExqxtLasR_B1vwLaebj3IGp6ItcWwaJfLp2bDKMPeHTg
		String token = "LFzpt02y9piL063yll0GVowaEcknGOX_J_hDgsqucdBDM560NEkKxFCYj2X6n0_qBFZD7kcGvIasc0p05PXsKpJtXTXv49AUcDDYeqqh7y5dQkd_5Py3n32n4qcUQAtbNI6983wOhWlCB1H7p4AXqg";
		AccessToken at = new AccessToken();
		at.setToken(token);
//		at = getToken();
		System.out.println(at.getToken());
	
//		getUsers(at);
		
		sendMessage(at);
		
//		MenuManager.createMenu(at);
		
//		WeiXinUtil.getMenu(at.getToken());
	}
	
	public static AccessToken getToken() {
		// 第三方用户唯一凭证
		String appId = "wx559fe47f592f5175";
		// 第三方用户唯一凭证密钥
		String appSecret = "0f841f5df93c8ec03abef37d78bdf599";

		// 调用接口获取access_token
		AccessToken at = WeiXinUtil.getAccessToken(appId, appSecret);
		
		return at;
	}
	
	//http请求方式: POST
	public static final String send_message_url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN";
	
	public static void sendMessage(AccessToken at) {
		String requestUrl = send_message_url.replace("ACCESS_TOKEN", at.getToken());
		
		String message = "{\"touser\":\"ozy1-uKxT6c65Ly0fHbSI4MyXX8A\",\"msgtype\":\"text\",\"text\":{\"content\":\"Just for test!\"}}";
		
		JSONObject json = WeiXinUtil.httpRequest(requestUrl, "POST", message);
		
		System.out.println(json);
		
	}
	
	public static void getUsers(AccessToken at) {
		List<WeixinUser> list = WeiXinUtil.getUsers(at.getToken());
		for (WeixinUser user : list) {
			System.out.println(user);
		}
	}
}
